package com.daka.controller;

import com.daka.entity.Activity;
import com.daka.entity.Group;
import com.daka.entity.GroupVolunteer;
import com.daka.enumerate.StatusCode;
import com.daka.service.ActivityService;
import com.daka.service.GroupService;
import com.daka.service.GroupVolunteerService;
import com.daka.vo.response.DataResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangx
 * Date: 2016/8/11 0015
 * Time: 14:25
 */
@Controller
@RequestMapping("/index")
@Slf4j
public class IndexController {

    @Autowired
    private ActivityService activityService;
    @Autowired
    private GroupService groupService;
    @Autowired
    private GroupVolunteerService groupVolunteerService;


    @ResponseBody
    @RequestMapping(value = "/index")
    public DataResponseVo<Object> index(@RequestParam(value = "groupId")Long groupId,@RequestParam(value = "volunteerId")String volunteerId){
        try {
            Map<String ,Object> map = new HashMap<String, Object>();
            //组织-活动数
            Activity activity = new Activity();
            activity.setGroupId(groupId);
            int act = activityService.selectCountByGroup(groupId);
            map.put("act",act);
            //组织-志愿者数
            GroupVolunteer groupVolunteer = new GroupVolunteer();
            groupVolunteer.setGroupId(groupId);
            int vol = groupVolunteerService.selectByStatementCount(groupVolunteer);
            map.put("vol",vol);
            //个人管理的组织列表
            List<Group> list = groupService.queryListByVolunteer(Long.valueOf(volunteerId));
            map.put("groupList",list);
            //活动
            //SELECT * FROM U_ACTIVITY WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CREATE_TIME, '%Y%m' ) ) =0/1/2/3/4/5/
            List<Activity> list1 = activityService.selectByPrimaryKey1();



            return new DataResponseVo<Object>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(),list1);
        }catch (Exception e){
            e.printStackTrace();
            return new DataResponseVo<Object>(StatusCode.SYS_ERROR.getCode(), StatusCode.SYS_ERROR.getMessage());
        }
    }


}










